package com.siruier.boss.ui.helper

import com.lahm.library.EasyProtectorLib
import com.siruier.boss.bean.DeviceInfoBean
import com.siruier.boss.ui.AppCore
import java.net.NetworkInterface
import java.util.*

object DeviceInfoHelper {

    @JvmStatic
    fun getDeviceInfoBean() = DeviceInfoBean(
        EasyProtectorLib.checkIsRoot(),
        EasyProtectorLib.checkIsBeingTracedByJava(),
        EasyProtectorLib.checkIsXposedExist(),
        EasyProtectorLib.checkIsRunningInVirtualApk("nvp", null),
        EasyProtectorLib.checkIsRunningInEmulator(AppCore.app, null),
        isVpnConnected(),
    )

    @JvmStatic
    fun isVpnConnected(): Boolean {
        try {
            val niList = NetworkInterface.getNetworkInterfaces()
            if (niList != null) {
                for (intf in Collections.list(niList)) {
                    if (!intf.isUp || intf.interfaceAddresses.size == 0) {
                        continue
                    }
                    if ("tun0" == intf.name || "ppp0" == intf.name) {
                        return true
                    }
                }
            }
        } catch (e: Throwable) {
            e.printStackTrace()
        }
        return false
    }
}